package com.leyou.item.controller;

import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.service.TbSpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("spec")
public class SpecParamController {

    @Autowired
    private TbSpecParamService specParamService;



    /*加参数cid和Searching*/
    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>> findSpecParam(@RequestParam(value = "gid",required =false) Long gid,
                                                            @RequestParam(value = "cid",required = false)Long cid,
                                                            @RequestParam(value = "searching" ,required = false)Boolean searching){


        List<SpecParamDTO> specParamDTOList=specParamService.findSpecParam(gid,cid,searching);

        return  ResponseEntity.status(HttpStatus.OK).body(specParamDTOList);
    }

    @PostMapping("/param")
    public ResponseEntity<Void> insertParam(@RequestBody SpecParamDTO specParamDTO){

        specParamService.insertParam(specParamDTO);

        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    @PutMapping("/param")
    public ResponseEntity<Void> updateParam(@RequestBody SpecParamDTO specParamDTO){

        specParamService.updateParam(specParamDTO);

        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }

    @DeleteMapping("param/{id}")
    public ResponseEntity<Void> deleteParam(@PathVariable("id") Long id){
        specParamService.deleteParam(id);
        return ResponseEntity.status(HttpStatus.OK).build();
    }
}
